﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.Object
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System.Runtime.InteropServices;
using System.Security;
using UnityEngine.Internal;
using UnityEngineInternal;

#nullable disable
namespace UnityEngine
{
  /// <summary>
  ///   <para>Base class for all objects Unity can reference.</para>
  /// </summary>
  [StructLayout(LayoutKind.Sequential)]
  public class Object
  {
    private IntPtr m_CachedPtr;
    private int m_InstanceID;
    private string m_UnityRuntimeErrorString;
    internal static int OffsetOfInstanceIDInCPlusPlusObject = -1;
    private const string objectIsNullMessage = "The Object you want to instantiate is null.";
    private const string cloneDestroyedMessage = "Instantiate failed because the clone was destroyed during creation. This can happen if DestroyImmediate is called in MonoBehaviour.Awake.";

    /// <summary>
    ///   <para>Gets  the instance ID of the object.</para>
    /// </summary>
    /// <returns>
    ///   <para>Returns the instance ID of the object. When used to call the origin object, this method returns a positive value. When used to call the instance object, this method returns a negative value.</para>
    /// </returns>
    [SecuritySafeCritical]
    public int GetInstanceID()
    {
      this.EnsureRunningOnMainThread();
      return this.m_InstanceID;
    }

    public override int GetHashCode() => this.m_InstanceID;

    public override bool Equals(object other)
    {
      Object rhs = other as Object;
      return (!(rhs == (Object) null) || other == null || other is Object) && Object.CompareBaseObjects(this, rhs);
    }

    public static implicit operator bool(Object exists)
    {
      return !Object.CompareBaseObjects(exists, (Object) null);
    }

    private static bool CompareBaseObjects(Object lhs, Object rhs)
    {
      bool flag1 = (object) lhs == null;
      bool flag2 = (object) rhs == null;
      if (flag2 & flag1)
        return true;
      if (flag2)
        return !Object.IsNativeObjectAlive(lhs);
      return flag1 ? !Object.IsNativeObjectAlive(rhs) : lhs.m_InstanceID == rhs.m_InstanceID;
    }

    private void EnsureRunningOnMainThread()
    {
      if (!Object.CurrentThreadIsMainThread())
        throw new InvalidOperationException("EnsureRunningOnMainThread can only be called from the main thread");
    }

    private static bool IsNativeObjectAlive(Object o)
    {
      if (o.GetCachedPtr() != IntPtr.Zero)
        return true;
      return !(o is MonoBehaviour) && !(o is ScriptableObject) && Object.DoesObjectWithInstanceIDExist(o.GetInstanceID());
    }

    private IntPtr GetCachedPtr() => this.m_CachedPtr;

    /// <summary>
    ///   <para>The name of the object.</para>
    /// </summary>
    public string name
    {
      get => Object.GetName(this);
      set => Object.SetName(this, value);
    }

    /// <summary>
    ///   <para>Clones the object original and returns the clone.</para>
    /// </summary>
    /// <param name="original">An existing object that you want to make a copy of.</param>
    /// <param name="position">Position for the new object.</param>
    /// <param name="rotation">Orientation of the new object.</param>
    /// <param name="parent">Parent that will be assigned to the new object.</param>
    /// <param name="instantiateInWorldSpace">When you assign a parent Object, pass true to position the new object directly in world space. Pass false to set the Object’s position relative to its new parent.</param>
    /// <returns>
    ///   <para>The instantiated clone.</para>
    /// </returns>
    [TypeInferenceRule(TypeInferenceRules.TypeOfFirstArgument)]
    public static Object Instantiate(Object original, Vector3 position, Quaternion rotation)
    {
      Object.CheckNullArgument((object) original, "The Object you want to instantiate is null.");
      if (original is ScriptableObject)
        throw new ArgumentException("Cannot instantiate a ScriptableObject with a position and rotation");
      Object @object = Object.Internal_InstantiateSingle(original, position, rotation);
      return !(@object == (Object) null) ? @object : throw new UnityException("Instantiate failed because the clone was destroyed during creation. This can happen if DestroyImmediate is called in MonoBehaviour.Awake.");
    }

    /// <summary>
    ///   <para>Clones the object original and returns the clone.</para>
    /// </summary>
    /// <param name="original">An existing object that you want to make a copy of.</param>
    /// <param name="position">Position for the new object.</param>
    /// <param name="rotation">Orientation of the new object.</param>
    /// <param name="parent">Parent that will be assigned to the new object.</param>
    /// <param name="instantiateInWorldSpace">When you assign a parent Object, pass true to position the new object directly in world space. Pass false to set the Object’s position relative to its new parent.</param>
    /// <returns>
    ///   <para>The instantiated clone.</para>
    /// </returns>
    [TypeInferenceRule(TypeInferenceRules.TypeOfFirstArgument)]
    public static Object Instantiate(
      Object original,
      Vector3 position,
      Quaternion rotation,
      Transform parent)
    {
      if ((Object) parent == (Object) null)
        return Object.Instantiate(original, position, rotation);
      Object.CheckNullArgument((object) original, "The Object you want to instantiate is null.");
      Object @object = Object.Internal_InstantiateSingleWithParent(original, parent, position, rotation);
      return !(@object == (Object) null) ? @object : throw new UnityException("Instantiate failed because the clone was destroyed during creation. This can happen if DestroyImmediate is called in MonoBehaviour.Awake.");
    }

    /// <summary>
    ///   <para>Clones the object original and returns the clone.</para>
    /// </summary>
    /// <param name="original">An existing object that you want to make a copy of.</param>
    /// <param name="position">Position for the new object.</param>
    /// <param name="rotation">Orientation of the new object.</param>
    /// <param name="parent">Parent that will be assigned to the new object.</param>
    /// <param name="instantiateInWorldSpace">When you assign a parent Object, pass true to position the new object directly in world space. Pass false to set the Object’s position relative to its new parent.</param>
    /// <returns>
    ///   <para>The instantiated clone.</para>
    /// </returns>
    [TypeInferenceRule(TypeInferenceRules.TypeOfFirstArgument)]
    public static Object Instantiate(Object original)
    {
      Object.CheckNullArgument((object) original, "The Object you want to instantiate is null.");
      Object @object = Object.Internal_CloneSingle(original);
      return !(@object == (Object) null) ? @object : throw new UnityException("Instantiate failed because the clone was destroyed during creation. This can happen if DestroyImmediate is called in MonoBehaviour.Awake.");
    }

    /// <summary>
    ///   <para>Clones the object original and returns the clone.</para>
    /// </summary>
    /// <param name="original">An existing object that you want to make a copy of.</param>
    /// <param name="position">Position for the new object.</param>
    /// <param name="rotation">Orientation of the new object.</param>
    /// <param name="parent">Parent that will be assigned to the new object.</param>
    /// <param name="instantiateInWorldSpace">When you assign a parent Object, pass true to position the new object directly in world space. Pass false to set the Object’s position relative to its new parent.</param>
    /// <returns>
    ///   <para>The instantiated clone.</para>
    /// </returns>
    [TypeInferenceRule(TypeInferenceRules.TypeOfFirstArgument)]
    public static Object Instantiate(Object original, Transform parent)
    {
      return Object.Instantiate(original, parent, false);
    }

    /// <summary>
    ///   <para>Clones the object original and returns the clone.</para>
    /// </summary>
    /// <param name="original">An existing object that you want to make a copy of.</param>
    /// <param name="position">Position for the new object.</param>
    /// <param name="rotation">Orientation of the new object.</param>
    /// <param name="parent">Parent that will be assigned to the new object.</param>
    /// <param name="instantiateInWorldSpace">When you assign a parent Object, pass true to position the new object directly in world space. Pass false to set the Object’s position relative to its new parent.</param>
    /// <returns>
    ///   <para>The instantiated clone.</para>
    /// </returns>
    [TypeInferenceRule(TypeInferenceRules.TypeOfFirstArgument)]
    public static Object Instantiate(
      Object original,
      Transform parent,
      bool instantiateInWorldSpace)
    {
      if ((Object) parent == (Object) null)
        return Object.Instantiate(original);
      Object.CheckNullArgument((object) original, "The Object you want to instantiate is null.");
      Object @object = Object.Internal_CloneSingleWithParent(original, parent, instantiateInWorldSpace);
      return !(@object == (Object) null) ? @object : throw new UnityException("Instantiate failed because the clone was destroyed during creation. This can happen if DestroyImmediate is called in MonoBehaviour.Awake.");
    }

    public static T Instantiate<T>(T original) where T : Object
    {
      Object.CheckNullArgument((object) original, "The Object you want to instantiate is null.");
      T obj = (T) Object.Internal_CloneSingle((Object) original);
      return !((Object) obj == (Object) null) ? obj : throw new UnityException("Instantiate failed because the clone was destroyed during creation. This can happen if DestroyImmediate is called in MonoBehaviour.Awake.");
    }

    public static T Instantiate<T>(T original, Vector3 position, Quaternion rotation) where T : Object
    {
      return (T) Object.Instantiate((Object) original, position, rotation);
    }

    public static T Instantiate<T>(
      T original,
      Vector3 position,
      Quaternion rotation,
      Transform parent)
      where T : Object
    {
      return (T) Object.Instantiate((Object) original, position, rotation, parent);
    }

    public static T Instantiate<T>(T original, Transform parent) where T : Object
    {
      return Object.Instantiate<T>(original, parent, false);
    }

    public static T Instantiate<T>(T original, Transform parent, bool worldPositionStays) where T : Object
    {
      return (T) Object.Instantiate((Object) original, parent, worldPositionStays);
    }

    /// <summary>
    ///   <para>Removes a GameObject, component or asset.</para>
    /// </summary>
    /// <param name="obj">The object to destroy.</param>
    /// <param name="t">The optional amount of time to delay before destroying the object.</param>
    public static void Destroy(Object obj, [DefaultValue("0.0F")] float t)
    {
      throw new NotImplementedException();
    }

    /// <summary>
    ///   <para>Removes a GameObject, component or asset.</para>
    /// </summary>
    /// <param name="obj">The object to destroy.</param>
    /// <param name="t">The optional amount of time to delay before destroying the object.</param>
    [ExcludeFromDocs]
    public static void Destroy(Object obj)
    {
      float t = 0.0f;
      Object.Destroy(obj, t);
    }

    /// <summary>
    ///   <para>Destroys the object obj immediately. You are strongly recommended to use Destroy instead.</para>
    /// </summary>
    /// <param name="obj">Object to be destroyed.</param>
    /// <param name="allowDestroyingAssets">Set to true to allow assets to be destroyed.</param>
    public static   void DestroyImmediate(Object obj, [DefaultValue("false")] bool allowDestroyingAssets)
    {
      throw new NotImplementedException();
    }

    /// <summary>
    ///   <para>Destroys the object obj immediately. You are strongly recommended to use Destroy instead.</para>
    /// </summary>
    /// <param name="obj">Object to be destroyed.</param>
    /// <param name="allowDestroyingAssets">Set to true to allow assets to be destroyed.</param>
    [ExcludeFromDocs]
    public static void DestroyImmediate(Object obj)
    {
      bool allowDestroyingAssets = false;
      Object.DestroyImmediate(obj, allowDestroyingAssets);
    }

    /// <summary>
    ///   <para>Gets a list of all loaded objects of Type type.</para>
    /// </summary>
    /// <param name="type">The type of object to find.</param>
    /// <param name="includeInactive">If true, components attached to inactive GameObjects are also included.</param>
    /// <returns>
    ///   <para>The array of objects found matching the type specified.</para>
    /// </returns>
    public static Object[] FindObjectsOfType(System.Type type)
    {
      return Object.FindObjectsOfType(type, false);
    }

    /// <summary>
    ///   <para>Gets a list of all loaded objects of Type type.</para>
    /// </summary>
    /// <param name="type">The type of object to find.</param>
    /// <param name="includeInactive">If true, components attached to inactive GameObjects are also included.</param>
    /// <returns>
    ///   <para>The array of objects found matching the type specified.</para>
    /// </returns>
    public static   Object[] FindObjectsOfType(System.Type type, bool includeInactive)
    {
      throw new NotImplementedException();
    }

    /// <summary>
    ///   <para>Retrieves a list of all loaded objects of Type type.</para>
    /// </summary>
    /// <param name="type">The type of object to find.</param>
    /// <param name="findObjectsInactive">Whether to include components attached to inactive GameObjects. If you don't specify this parameter, this function doesn't include inactive objects in the results.</param>
    /// <param name="sortMode">Whether and how to sort the returned array. Not sorting the array makes this function run significantly faster.</param>
    /// <returns>
    ///   <para>The array of objects found matching the type specified.</para>
    /// </returns>
    public static Object[] FindObjectsByType(System.Type type, FindObjectsSortMode sortMode)
    {
      return Object.FindObjectsByType(type, FindObjectsInactive.Exclude, sortMode);
    }

    /// <summary>
    ///   <para>Retrieves a list of all loaded objects of Type type.</para>
    /// </summary>
    /// <param name="type">The type of object to find.</param>
    /// <param name="findObjectsInactive">Whether to include components attached to inactive GameObjects. If you don't specify this parameter, this function doesn't include inactive objects in the results.</param>
    /// <param name="sortMode">Whether and how to sort the returned array. Not sorting the array makes this function run significantly faster.</param>
    /// <returns>
    ///   <para>The array of objects found matching the type specified.</para>
    /// </returns>
    public static   Object[] FindObjectsByType(
      System.Type type,
      FindObjectsInactive findObjectsInactive,
      FindObjectsSortMode sortMode)
    {
      throw new NotImplementedException();
    }

    /// <summary>
    ///   <para>Do not destroy the target Object when loading a new Scene.</para>
    /// </summary>
    /// <param name="target">An Object not destroyed on Scene change.</param>
    public static   void DontDestroyOnLoad(Object target)
    {
      throw new NotImplementedException();
    }

    /// <summary>
    ///   <para>Should the object be hidden, saved with the Scene or modifiable by the user?</para>
    /// </summary>
    public   HideFlags hideFlags {   get;   set; }

    [Obsolete("use Object.Destroy instead.")]
    public static void DestroyObject(Object obj, [DefaultValue("0.0F")] float t)
    {
      Object.Destroy(obj, t);
    }

    [Obsolete("use Object.Destroy instead.")]
    [ExcludeFromDocs]
    public static void DestroyObject(Object obj)
    {
      float t = 0.0f;
      Object.Destroy(obj, t);
    }

    [Obsolete("warning use Object.FindObjectsByType instead.")]
    public static Object[] FindSceneObjectsOfType(System.Type type)
    {
      return Object.FindObjectsOfType(type);
    }

    public static T[] FindObjectsOfType<T>() where T : Object
    {
      return Resources.ConvertObjects<T>(Object.FindObjectsOfType(typeof (T), false));
    }

    public static T[] FindObjectsByType<T>(FindObjectsSortMode sortMode) where T : Object
    {
      return Resources.ConvertObjects<T>(Object.FindObjectsByType(typeof (T), FindObjectsInactive.Exclude, sortMode));
    }

    public static T[] FindObjectsOfType<T>(bool includeInactive) where T : Object
    {
      return Resources.ConvertObjects<T>(Object.FindObjectsOfType(typeof (T), includeInactive));
    }

    public static T[] FindObjectsByType<T>(
      FindObjectsInactive findObjectsInactive,
      FindObjectsSortMode sortMode)
      where T : Object
    {
      return Resources.ConvertObjects<T>(Object.FindObjectsByType(typeof (T), findObjectsInactive, sortMode));
    }

    public static T FindObjectOfType<T>() where T : Object
    {
      return (T) Object.FindObjectOfType(typeof (T), false);
    }

    public static T FindObjectOfType<T>(bool includeInactive) where T : Object
    {
      return (T) Object.FindObjectOfType(typeof (T), includeInactive);
    }

    public static T FindFirstObjectByType<T>() where T : Object
    {
      return (T) Object.FindFirstObjectByType(typeof (T), FindObjectsInactive.Exclude);
    }

    public static T FindAnyObjectByType<T>() where T : Object
    {
      return (T) Object.FindAnyObjectByType(typeof (T), FindObjectsInactive.Exclude);
    }

    public static T FindFirstObjectByType<T>(FindObjectsInactive findObjectsInactive) where T : Object
    {
      return (T) Object.FindFirstObjectByType(typeof (T), findObjectsInactive);
    }

    public static T FindAnyObjectByType<T>(FindObjectsInactive findObjectsInactive) where T : Object
    {
      return (T) Object.FindAnyObjectByType(typeof (T), findObjectsInactive);
    }

    /// <summary>
    ///   <para>Returns a list of all active and inactive loaded objects of Type type.</para>
    /// </summary>
    /// <param name="type">The type of object to find.</param>
    /// <returns>
    ///   <para>The array of objects found matching the type specified.</para>
    /// </returns>
    [Obsolete("Please use Resources.FindObjectsOfTypeAll instead")]
    public static Object[] FindObjectsOfTypeAll(System.Type type)
    {
      return Resources.FindObjectsOfTypeAll(type);
    }

    private static void CheckNullArgument(object arg, string message)
    {
      if (arg == null)
        throw new ArgumentException(message);
    }

    /// <summary>
    ///   <para>Returns the first active loaded object of Type type.</para>
    /// </summary>
    /// <param name="type">The type of object to find.</param>
    /// <param name="includeInactive"></param>
    /// <returns>
    ///   <para>Object The first active loaded object that matches the specified type. It returns null if no Object matches the type.</para>
    /// </returns>
    [TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)]
    public static Object FindObjectOfType(System.Type type)
    {
      Object[] objectsOfType = Object.FindObjectsOfType(type, false);
      return objectsOfType.Length != 0 ? objectsOfType[0] : (Object) null;
    }

    /// <summary>
    ///   <para>Retrieves the first active loaded object of Type type.</para>
    /// </summary>
    /// <param name="type">The type of object to find.</param>
    /// <param name="findObjectsInactive">Whether to include components attached to inactive GameObjects. If you don't specify this parameter, this function doesn't include inactive objects in the results.</param>
    /// <returns>
    ///   <para>Returns the first active loaded object that matches the specified type. If no object matches the specified type, returns null.</para>
    /// </returns>
    public static Object FindFirstObjectByType(System.Type type)
    {
      Object[] objectsByType = Object.FindObjectsByType(type, FindObjectsInactive.Exclude, FindObjectsSortMode.InstanceID);
      return objectsByType.Length != 0 ? objectsByType[0] : (Object) null;
    }

    /// <summary>
    ///   <para>Retrieves any active loaded object of Type type.</para>
    /// </summary>
    /// <param name="type">The type of object to find.</param>
    /// <param name="findObjectsInactive">Whether to include components attached to inactive GameObjects. If you don't specify this parameter, this function doesn't include inactive objects in the results.</param>
    /// <returns>
    ///   <para>Returns an arbitrary active loaded object that matches the specified type. If no object matches the specified type, returns null.</para>
    /// </returns>
    public static Object FindAnyObjectByType(System.Type type)
    {
      Object[] objectsByType = Object.FindObjectsByType(type, FindObjectsInactive.Exclude, FindObjectsSortMode.None);
      return objectsByType.Length != 0 ? objectsByType[0] : (Object) null;
    }

    /// <summary>
    ///   <para>Returns the first active loaded object of Type type.</para>
    /// </summary>
    /// <param name="type">The type of object to find.</param>
    /// <param name="includeInactive"></param>
    /// <returns>
    ///   <para>Object The first active loaded object that matches the specified type. It returns null if no Object matches the type.</para>
    /// </returns>
    [TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)]
    public static Object FindObjectOfType(System.Type type, bool includeInactive)
    {
      Object[] objectsOfType = Object.FindObjectsOfType(type, includeInactive);
      return objectsOfType.Length != 0 ? objectsOfType[0] : (Object) null;
    }

    /// <summary>
    ///   <para>Retrieves the first active loaded object of Type type.</para>
    /// </summary>
    /// <param name="type">The type of object to find.</param>
    /// <param name="findObjectsInactive">Whether to include components attached to inactive GameObjects. If you don't specify this parameter, this function doesn't include inactive objects in the results.</param>
    /// <returns>
    ///   <para>Returns the first active loaded object that matches the specified type. If no object matches the specified type, returns null.</para>
    /// </returns>
    public static Object FindFirstObjectByType(System.Type type, FindObjectsInactive findObjectsInactive)
    {
      Object[] objectsByType = Object.FindObjectsByType(type, findObjectsInactive, FindObjectsSortMode.InstanceID);
      return objectsByType.Length != 0 ? objectsByType[0] : (Object) null;
    }

    /// <summary>
    ///   <para>Retrieves any active loaded object of Type type.</para>
    /// </summary>
    /// <param name="type">The type of object to find.</param>
    /// <param name="findObjectsInactive">Whether to include components attached to inactive GameObjects. If you don't specify this parameter, this function doesn't include inactive objects in the results.</param>
    /// <returns>
    ///   <para>Returns an arbitrary active loaded object that matches the specified type. If no object matches the specified type, returns null.</para>
    /// </returns>
    public static Object FindAnyObjectByType(System.Type type, FindObjectsInactive findObjectsInactive)
    {
      Object[] objectsByType = Object.FindObjectsByType(type, findObjectsInactive, FindObjectsSortMode.None);
      return objectsByType.Length != 0 ? objectsByType[0] : (Object) null;
    }

    /// <summary>
    ///   <para>Returns the name of the object.</para>
    /// </summary>
    /// <returns>
    ///   <para>The name returned by ToString.</para>
    /// </returns>
    public override string ToString() => Object.ToString(this);

    public static bool operator ==(Object x, Object y) => Object.CompareBaseObjects(x, y);

    public static bool operator !=(Object x, Object y) => !Object.CompareBaseObjects(x, y);

     
    private static   int GetOffsetOfInstanceIDInCPlusPlusObject()
    {
      throw new NotImplementedException();
    }

     
    private static   bool CurrentThreadIsMainThread()
    {
      throw new NotImplementedException();
    }

     
    private static   Object Internal_CloneSingle(  Object data)
    {
      using (Stream objectStream = new MemoryStream())
      {
        // 使用二进制格式化器序列化原始对象
        var formatter = new BinaryFormatter();
        formatter.Serialize(objectStream, original);
        objectStream.Seek(0, SeekOrigin.Begin);
        // 反序列化对象的拷贝
        return (T)formatter.Deserialize(objectStream);
      }
    }

     
    private static   Object Internal_CloneSingleWithParent(
        Object data,
        Transform parent,
      bool worldPositionStays)
    {
      throw new NotImplementedException();
    }

    private static Object Internal_InstantiateSingle(  Object data, Vector3 pos, Quaternion rot)
    {
      return Object.Internal_InstantiateSingle_Injected(data, ref pos, ref rot);
    }

    private static Object Internal_InstantiateSingleWithParent(
        Object data,
        Transform parent,
      Vector3 pos,
      Quaternion rot)
    {
      return Object.Internal_InstantiateSingleWithParent_Injected(data, parent, ref pos, ref rot);
    }

     
    private static   string ToString(Object obj)
    {
      throw new NotImplementedException();
    }

     
    private static   string GetName(  Object obj)
    {
      throw new NotImplementedException();
    }

     
    internal static   bool IsPersistent(  Object obj)
    {
      throw new NotImplementedException();
    }

     
    private static   void SetName(  Object obj, string name)
    {
      throw new NotImplementedException();
    }

     
    internal static   bool DoesObjectWithInstanceIDExist(int instanceID)
    {
      throw new NotImplementedException();
    }

    internal static   Object FindObjectFromInstanceID(int instanceID)
    {
      throw new NotImplementedException();
    }

    internal static   Object ForceLoadFromInstanceID(int instanceID)
    {
      throw new NotImplementedException();
    }

     
    private static   Object Internal_InstantiateSingle_Injected(
      Object data,
      ref Vector3 pos,
      ref Quaternion rot)
    {
      throw new NotImplementedException();
    }

     
    private static   Object Internal_InstantiateSingleWithParent_Injected(
      Object data,
      Transform parent,
      ref Vector3 pos,
      ref Quaternion rot)
    {
      throw new NotImplementedException();
    }
  }
}
